package Control;

import java.util.Comparator;

public class CharacterAffine {
	private Character character;
	private int affinity;
	public static AffinityComparator comparator = new AffinityComparator();
	
	public CharacterAffine(Character character) {
		super();
		this.character = character;
		this.affinity = 1;
	}

	public int getAffinity() {
		return affinity;
	}

	public Character getCharacter() {
		return character;
	}

	public void incrAffinity(int affinity) {
		this.affinity += affinity;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((character == null) ? 0 : character.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CharacterAffine other = (CharacterAffine) obj;
		if (character == null) {
			if (other.character != null)
				return false;
		} else if (!character.equals(other.character))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "CharacterAffine =" + character.getShortName() + ", affinity="
				+ affinity ;
	}

	
	public static class AffinityComparator implements Comparator{

		@Override
		public int compare(Object o0, Object o1) {
			if(!o0.getClass().equals(CharacterAffine.class) || (!o1.getClass().equals(CharacterAffine.class)))
				return 0;
			CharacterAffine a0, a1;
			a0 = (CharacterAffine)o0;
			a1 = (CharacterAffine)o1;
			if(a0.getAffinity() > a1.getAffinity())
				return -1;
			if(a0.getAffinity() < a1.getAffinity())
				return 1;
			return 0;
		}
		
	}
	
	
	
	
}
